//泰州影像图WMTS
define([
    "dojo/_base/declare"
    , "esri/layers/TiledMapServiceLayer"
    , "esri/SpatialReference"
    , "esri/geometry/Extent"
    , "esri/layers/TileInfo"
], function (declare
    , TiledMapServiceLayer
    , SpatialReference
    , Extent
    , TileInfo) {
    var Tz_img_c = declare([TiledMapServiceLayer], {
        declaredClass: "tz.WMTSLayer",
        constructor: function (o) {
            this.version = o.version || "1.0.0";
            this.title = o.title || 'UAV_10架次_20181225';
            this.identifier = o.identifier || "BBC6F90B-2D7B-4491-9663-69AA23791F89";
            this.imageFormat = o.imageFormat || "image/png";
            this.tilematrixset = o.tilematrixset || "1562052216";
            this.port = o.port || '8008';
            var sr = o.sr || {wkid: 4326};
            this.spatialReference = new SpatialReference(sr);
            var extent = o.extent || {
                xMin: 119.94616434834,
                yMin: 32.0181159284892,
                xMax: 120.00730792557,
                yMax: 32.0883592140575
            };
            this.initialExtent = new Extent(extent.xMin, extent.yMin, extent.xMax, extent.yMax, this.spatialReference);
            this.fullExtent = this.initialExtent;
            this.tileInfo = new TileInfo({
                "dpi": "90.71428571427429",
                "format": "image/png",
                "compressionQuality": 0,
                "spatialReference": sr,
                "rows": 256,
                "cols": 256,
                "origin": {
                    "x": -180,
                    "y": 90
                },
                "lods": [
                    {
                        "level": 0,
                        "scale": 2.792281947544292e+8,
                        "resolution": 0.703125
                    }, {
                        "level": 1,
                        "scale": 1.396140973772146e+8,
                        "resolution": 0.3515625
                    }, {
                        "level": 2,
                        "scale": 6.98070486886073e+7,
                        "resolution": 0.17578125
                    }, {
                        "level": 3,
                        "scale": 3.490352434430365e+7,
                        "resolution": 0.087890625
                    }, {
                        "level": 4,
                        "scale": 1.7451762172151826e+7,
                        "resolution": 0.0439453125
                    }, {
                        "level": 5,
                        "scale": 8.725881086075913e+6,
                        "resolution": 0.02197265625
                    }, {
                        "level": 6,
                        "scale": 4.362940543037957e+6,
                        "resolution": 0.010986328125
                    }, {
                        "level": 7,
                        "scale": 2.1814702715189783e+6,
                        "resolution": 0.0054931640625
                    }, {
                        "level": 8,
                        "scale": 1.0907351357594891e+6,
                        "resolution": 0.00274658203125
                    }, {
                        "level": 9,
                        "scale": 5.453675678797446e+5,
                        "resolution": 0.001373291015625
                    }, {
                        "level": 10,
                        "scale": 2.726837839398723e+5,
                        "resolution": 6.866455078125e-4
                    }, {
                        "level": 11,
                        "scale": 1.3634189196993614e+5,
                        "resolution": 3.4332275390625e-4
                    }, {
                        "level": 12,
                        "scale": 6.817094598496807e+4,
                        "resolution": 1.71661376953125e-4
                    }, {
                        "level": 13,
                        "scale": 3.4085472992484036e+4,
                        "resolution": 8.58306884765625e-5
                    }, {
                        "level": 14,
                        "scale": 1.7042736496242018e+4,
                        "resolution": 4.291534423828125e-5
                    }, {
                        "level": 15,
                        "scale": 8521.368248121009,
                        "resolution": 2.1457672119140625e-5
                    }, {
                        "level": 16,
                        "scale": 4260.6841240605045,
                        "resolution": 1.0728836059570313e-5
                    }, {
                        "level": 17,
                        "scale": 2130.3420620302522,
                        "resolution": 5.364418029785156e-6
                    }, {
                        "level": 18,
                        "scale": 1065.1710310151261,
                        "resolution": 2.682209014892578e-6
                    }, {
                        "level": 19,
                        "scale": 532.5855155075631,
                        "resolution": 1.341104507446289e-6
                    }, {
                        "level": 20,
                        "scale": 266.29275775378153,
                        "resolution": 6.705522537231445e-7
                    },
                    {
                        "level": 21,
                        "scale": 133.14637887689076,
                        "resolution": 3.3527612686157227e-7
                    }
                ]
            });
            this.loaded = true;
            this.onLoad(this);
        },
        getTileUrl: function (level, row, col) {
            var urlTemplate = `http://122.112.226.169:${this.port}/mapservice?res=${this.identifier}&layer=image&style=default&tilematrixset=l&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix=${level}&TileCol=${col}&TileRow=${row}`
            // var urlTemplate = `http://122.112.226.169:8008/${this.title}/wmts?layer=${this.identifier}&style=default&tilematrixset=${this.tilematrixset}&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix=${level}&TileCol=${col}&TileRow=${row}`
            return urlTemplate;
        }
    });
    return Tz_img_c;
});